﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using KqAutoDesign.Base;

namespace KqAutoDesign.Models
{
    public class TaskInfo:NotifyBase, IClone<TaskInfo>
    {
        public TaskInfo() 
        {
            Id = -1;
            _queueId = -1;
            IsSelected = false;
            _queueIdTxt = "未加入队列";
        }
        private int _id;
        public int Id 
        {
            get { return _id; }
            set
            {
                _id = value;
                OnPropertyChanged(nameof(Id));  
            }
        }
        private bool _isSelected;
        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                if (_isSelected != value)
                {
                    _isSelected = value;
                    OnPropertyChanged(nameof(IsSelected));
                    //CommandManager.InvalidateRequerySuggested();
                }
            }
        }
        public string Name { get; set; }
        public string Path {  get; set; }
        public WorkFlowStateEnum StatuDescription
        {
            get { return WorkFlow.WorkFlowState; }
            set
            {
                if(value != WorkFlow.WorkFlowState)
                {
                    WorkFlow.WorkFlowState = value;
                    OnPropertyChanged(nameof(StatuDescription));
                    Application.Current.Dispatcher.Invoke(() => CommandManager.InvalidateRequerySuggested());
                }
            }
        }

        private WorkFlowBase _wf;
        public WorkFlowBase WorkFlow 
        { 
            get{ return _wf; }
            set
            {
                if (_wf != value)
                {
                    _wf = value;
                    OnPropertyChanged(nameof(WorkFlow));
                }
            }
        }

        /// <summary>
        /// 运行队列编号
        /// </summary>
        private int _queueId;
        public int QueueId
        {
            get => _queueId;
            set
            {
                if (_queueId != value)
                {
                    _queueId = value;
                    QueueIdText = "任务队列序号:"+value;
                    OnPropertyChanged(nameof(QueueId));
                }
            }
        }

        private string _queueIdTxt;
        public string QueueIdText
        {
            get => _queueIdTxt;
            set
            {
                if (_queueIdTxt != value)
                {
                    _queueIdTxt = value;
                    OnPropertyChanged(nameof(QueueIdText));
                }
            }
        }

        public TaskInfo Clone()
        {
            var cloned = MemberwiseClone() as TaskInfo;
            cloned.WorkFlow = WorkFlow?.Clone();

            return cloned;
        }
    }
}
